package com.gmd.consultamedica.repository;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.gmd.consultamedica.model.ConsultaMedicaDAO;
import com.gmd.model.Consultamedica;

public class JPAConsultaMedicaDAO implements ConsultaMedicaDAO {

	EntityManager em;
	
	public JPAConsultaMedicaDAO(EntityManager em){
		this.em = em;
	}
	
	@Override
	public int getLastId() {
        Query query = em.createNamedQuery("getLastIdConsMed");
		Object result = query.getSingleResult();
		return (result != null) ? (Integer) result : 0;
	}

	@Override
	public Consultamedica insert(Consultamedica o) {
		em.persist(o);
		return o;
	}

}
